# -*- coding:utf-8 -*-
import sys, hashlib, os

def get_file_diggest(filename,):
    # 取文本中最长句子作为签名
    f = file(filename)
    longest_sents = ''
    max_length = 0
    for line in f:
        sents_list = line.strip().split('。')
        for s in sents_list:
            if len(s) > max_length:
                max_length = len(s)
                longest_sents = s
    return hashlib.md5(longest_sents).hexdigest()

if __name__ == '__main__':
    d = {}
    targetDir = sys.argv[1]
    targetSuffix = 'txt'
    for filename in os.listdir(targetDir):
        targetFile = os.path.join(targetDir,  filename)
        if os.path.isfile(targetFile):
            if filename[-3:] == targetSuffix:
                diggest = get_file_diggest(targetFile)
                if not d.has_key(diggest):
                    d[diggest] = filename
                else:
                    print d[diggest], filename

